package com.grm.juc.j02_daemonthread;

import java.util.concurrent.TimeUnit;

/**
 * desc: 开启一个线程Thread-A, 默认为用户线程，内部通过while循环使其无法结束。
 *
 * 用户线程，当主线程（main）结束后，线程Thread-A仍然无法结束。
 *
 * @author gaorimao
 * @since 2022-09-01 11:23:00
 */
public class MyUserThread {
    public static void main(String[] args) {
        Thread threadA = new Thread(() -> {
            boolean flag = Thread.currentThread().isDaemon();
            System.out.println(Thread.currentThread().getName() + " is " + (flag ? "守护线程" : "用户线程"));
            while (true) {
            }
        }, "Thread-A");


        threadA.start();

        //暂停几秒线程
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName() + " end.");
    }
}
